#include <iostream>
#include <string>
#include <fstream>
#include "bundle.h"
using namespace std;

int main(int argc, char* argv[])
{
    if(argc < 3)
    {
        cout << "请输入压缩目标文件名及压缩后的文件名" << endl;
        return -1;
    }

    string target_filename = argv[1];
    string pack_filename = argv[2];
    // 读取文件
    ifstream ifs;
    ifs.open(target_filename, std::ios::binary);
    ifs.seekg(0, ios_base::end);
    size_t fsize = ifs.tellg();
    ifs.seekg(0, ios_base::beg);

    string body;
    body.resize(fsize);
    ifs.read(&body[0], fsize);
    // 压缩字符串
    string pack = bundle::pack(bundle::LZIP, body);
    // 将压缩后的字符串写入到文件中
    ofstream ofs;
    ofs.open(pack_filename, ios_base::binary);
    ofs.write(&pack[0], pack.size());

    ifs.close();
    ofs.close();

    return 0;
}